package com.nets.pool;

import com.nets.client.Client;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author sig
 * @since 2016/9/17
 */
public class ClientPool {
    private static Map<String, Client> clientMap = new ConcurrentHashMap<>();

    public static Client create(String host, int port) {
        clientMap.putIfAbsent(host, new Client(host, port));
        return clientMap.get(host);
    }

    public static void shutdown() {
        clientMap.values().forEach(Client::shutdown);
        clientMap.clear();
    }
}
